<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
    <style type="text/css">
        /* tooltip */
        #tooltip{
            position:absolute;
            border:1px solid #ccc;
            background:#333;
            padding:2px;
            display:none;
            color:#fff;
        }
    </style>
</head>
<body style="padding:10px;">
<div class="tplay-body-div">
    <div class="layui-tab">
        <!--<ul class="layui-tab-title">-->
        <!--    <li class="layui-this">发放金额</li>-->
        <!--    <li><a href="{:url('admin/kxffhz/index')}" class="a_menu">款项发放汇总</a></li>-->
        <!--</ul>-->
    </div>
    <h1 align="center">{$zhu.name}的发放金额</h1>
    <br /><br />
    <?php if(!in_array($admin_cate_id,$operation)){ ?>
    <div style="text-align:center"><a class="layui-btn add" >添加款项发放</a></div>
    <?php } ?>
    <table class="layui-table" id="table" lay-filter="test1" lay-size="lg">
        <colgroup>
            <col width="180">
            <col width="180">
            <col width="130">
            <col width="150">
            <?php if(!in_array($admin_cate_id,$operation)){ ?>
            <col width="300">
            <?php } ?>
        </colgroup>
        <thead>

        <tr>
            <th align="center"><p align="center"><strong>款项发放日期</strong></p></th>
            <th align="center"><p align="center"><strong>金额（元）</strong></p></th>
            <th align="center"><p align="center"><strong>户主</strong></p></th>
            <th align="center"><p align="center"><strong>类型</strong></p></th>
            <th align="center"><p align="center"><strong>备注</strong></p></th>
            <?php if(!in_array($admin_cate_id,$operation)){ ?>
            <th align="center"><p align="center"><strong>操作</strong></p></th>
            <?php } ?>

        </tr>
        </thead>
        <tbody>
        {volist name="list" id="vo"}
        <tr>
            <td align="center">{$vo.rq}</td>
            <td align="center">{$vo.money}</td>
            <td align="center">{$zhu.name}</td>
            <td align="center">{$vo.lx}</td>
            <td align="center">{$vo.bz}</td>
            <?php if(!in_array($admin_cate_id,$operation)){ ?>
            <td align="center">
                <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-primary delete" id="{$vo.id}" style="margin-right: 0;font-size:12px;"><i class="layui-icon"></i></a>
                <a onclick="edit('{$vo.id}')" class="layui-btn layui-btn-xs a_menu layui-btn-primary" style="margin-right: 0;font-size:12px;"><i class="layui-icon"></i></a>

            </td>
            <?php } ?>
        </tr>
        {/volist}

        <tr>
            <td><p align="center"><strong>总计：</strong></p></td>
            <td colspan="5"><p align="center"><strong>{$allMoney}</strong></p></td>
        </tr>
        </tbody>
    </table>
    <div style="padding:0 20px;"></div>
    {include file="public/foot"}
</div>

<script>

    //因为动态添加的元素class属性是无效的，所以不能用$('.add').click(function(){});
    $('body').on('click', '.add', function() {
        $('.add').hide();
        //你要添加的html
        var html = '<tr><form id="aaa">'+
            '<td><input type="text" class="layui-input" name="rq"></td>'+
            '<td><input type="text" class="layui-input" name="money"></td>'+
            '<td>保存自动生成</td>'+
            '<td><input type="text" class="layui-input" name="lx"></td>'+
            '<td><input type="text" class="layui-input" name="bz"></td></form>'+
            "<td>"+
            "<a class='layui-btn layui-btn-xs edit data-count-edit' lay-event='edit'>保存数据</a><a class='layui-btn del layui-btn-xs layui-btn-danger data-count-delete' lay-event='delete'>删除</a>"+
            "</td>"+
            '</tr>';
        // // console.log(html)
        // //添加到表格最后
        $(html).appendTo($('#table tbody:last'));
        // $(".layui-table-body .layui-table").append(html);
        // form.render();//因为有select元素，所有添加后要重新渲染一次
    });
    $('body').on('click', '.del', function() {
        if ($('#table tbody tr').length === 1) {
            layer.msg('只有一条不允许删除。', {
                time : 2000
            });
        } else {
            $(this).closest('tr').remove();
            $('.add').show();
        }
    });
    $(document).on('click','.edit',function(){
        $.ajax({
            url:'{:url("admin/kxffhz/info")}',
            async : false,    //表示请求是否异步处理
            type : "post",    //请求类型
            dataType : "json",//返回的数据类型
            data:{
                'pid':{$zhu.id},
                'rq':$("input[name='rq']").val(),
                'money':$("input[name='money']").val(),
                'lx':$("input[name='lx']").val(),
                'bz':$("input[name='bz']").val(),
            },
            success:function (res) {
                if (res == 200) {
                    layer.msg('操作成功', {
                        time : 2000
                    });
                    setTimeout(function(){
                        window.location.reload()
                    },2000);

                }
            },
            error:function (err) {
                console.log(err);
            }
        })
    })

    $('.delete').click(function(){
        var id = $(this).attr('id');
        layer.confirm('确定要删除?', function(index) {
            $.ajax({
                url:"{:url('admin/kxffhz/delete')}",
                data:{id:id},
                success:function(res) {
                    if(res.code == 1) {
                        layer.msg(res.msg);
                        setTimeout(function(){
                            location.reload();
                        },1500)

                    }else{
                        layer.msg(res.msg,{icon:1,time:3000});
                    }
                }
            })
        })
    })

    function edit(id){
        layer.open({
            type: 2,
            area: [600+'px', 600 +'px'],
            fix: false, //不固定
            maxmin: true,
            shadeClose: true,
            title: "编辑",
            content: "/admin/kxffhz/edit.shtml?id=+"+id
        })
    }
</script>
</body>
</html>